Ext.define('BISC.view.CtxMnuServer', {
    extend: 'Ext.menu.Menu',
    scope: this,
    listeners: {
        click: function( menu, item ) {
            switch( item.identifier ) {
                case 'update':
                    this.update();
                    break;
                case 'delete':
                    Ext.Msg.confirm('Remove Server', 'Are you sure you want remove "' + this.record.get('name') + '"?', function( btn, nothing, item ) {
                        if ( btn == 'yes' ) {
                            this.remove();
                        }
                    }, this);
                    break;
            }
        }
    },
    initComponent: function() {
        var me = this;

        Ext.applyIf(me, {
            items: [
                {
                    text: 'Edit',
                    iconCls: 'icon_editDevice',
                    identifier: 'update'
                },
                {
                    text: 'Remove',
                    iconCls: 'icon_removeDevice',
                    identifier: 'delete'
                }
            ]
        });
        me.callParent(arguments);
    },
    remove: function() {
        Ext.Ajax.request({
            url: 'http://localhost:8888/removeServer?serverId=' + this.record.get('id'),
            success: function() { Ext.getCmp('serversGrid').getStore().load() }
        });
    },
    update: function() {
        var me = this;
        var form = Ext.create( 'BISC.view.FormCreateServer', { record: this.record, mode: 'edit' } );
        var wndw = Ext.create('Ext.window.Window', {
            title: 'Edit Server',
            iconCls: 'icon_editDevice',
            modal: true,
			height: 260,
			width: 400,
            resizable: false,
            layout: 'fit',
            items: [
                form
            ]
        }).show();
        wndw.on( 'done', function() {
            wndw.close();
            Ext.getCmp('serversGrid').getStore().load();
        });
    }
});
